use std::convert::From;
use std::borrow::Borrow;
use std::ops::Deref;
#[derive(Debug)]
#[allow(dead_code)]
struct Number {
    value: i32,
}
impl From<i32> for Number {
    fn from(item: i32) -> Self {
        Number { value: item }
    }
}
fn main() {
//     1.From
//     把str转成String
    let my_str = "hello";
    let my_string = String::from(my_str);
    println!("str To string: {my_string:?}");

//     把i32转成Number
    let my_int = 5;
    let my_num = Number::from(my_int);
    println!("int To Number: {my_num:?}");
//     2.Into
//     把String转成str
    let my_string = String::from("hello");
    let my_str: &str = my_string.as_str();
    println!("string To str: {my_str:?}");
//     把Number转成i32
    let my_num = Number { value: 5 };
    let my_int: i32 = my_num.value;
    println!("Number To int: {my_int:?}");
    let int = 5;
    let num: Number = int.into();
    println!("int To Number: {num:?}");
//     3.AsRef
//     把String转成&str
    let my_string = String::from("hello");
    let my_str: &str = my_string.as_ref();
    println!("string To &str: {my_str:?}");
//     把Number转成&i32
    let my_num = Number { value: 5 };
    let my_int: &i32 = &my_num.value;
    println!("Number To &int: {my_int:?}");
//     4.AsMut
//     把String转成&mut str
    let mut my_string = String::from("hello");
    let my_str: &mut str = my_string.as_mut();
    println!("string To &mut str: {my_str:?}");
//     把Number转成&mut i32
    let mut my_num = Number { value: 5 };
    let my_int: &mut i32 = &mut my_num.value;
    println!("Number To &mut int: {my_int:?}");
//     5.Borrow
//     把String转成&str
    let my_string = String::from("hello");
    let my_str: &str = my_string.borrow();
    println!("string To &str: {my_str:?}");
//     把Number转成&i32
    let my_num = Number { value: 5 };
    let my_int: &i32 = my_num.value.borrow();
    println!("Number To &int: {my_int:?}");
//     6.Deref
//     把String转成&str
    let my_string = String::from("hello");
    let my_str: &str = my_string.deref();
    println!("string To &str: {my_str:?}");
}
